<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>重识音频 | 不眠</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="生活不仅需要氧气，更需要勇气">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.a6f4041f.css" as="style"><link rel="preload" href="/blog/assets/js/app.bd1ef45e.js" as="script"><link rel="preload" href="/blog/assets/js/3.ba154db2.js" as="script"><link rel="preload" href="/blog/assets/js/1.1f0d1f23.js" as="script"><link rel="preload" href="/blog/assets/js/12.2f9bf96e.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.707cbfdf.js"><link rel="prefetch" href="/blog/assets/js/11.72f1afb7.js"><link rel="prefetch" href="/blog/assets/js/13.05b7b31a.js"><link rel="prefetch" href="/blog/assets/js/14.44f18cf0.js"><link rel="prefetch" href="/blog/assets/js/15.6aafcdf2.js"><link rel="prefetch" href="/blog/assets/js/16.d4a57fd2.js"><link rel="prefetch" href="/blog/assets/js/17.067fa92a.js"><link rel="prefetch" href="/blog/assets/js/18.21af6bf6.js"><link rel="prefetch" href="/blog/assets/js/19.ad8e54ec.js"><link rel="prefetch" href="/blog/assets/js/20.50434d17.js"><link rel="prefetch" href="/blog/assets/js/21.95e1d5d1.js"><link rel="prefetch" href="/blog/assets/js/22.5bbb89a4.js"><link rel="prefetch" href="/blog/assets/js/23.49d7a9a4.js"><link rel="prefetch" href="/blog/assets/js/24.aaae9157.js"><link rel="prefetch" href="/blog/assets/js/25.889add58.js"><link rel="prefetch" href="/blog/assets/js/26.4b48b065.js"><link rel="prefetch" href="/blog/assets/js/27.b06fa976.js"><link rel="prefetch" href="/blog/assets/js/28.f78d3b25.js"><link rel="prefetch" href="/blog/assets/js/29.67ba4742.js"><link rel="prefetch" href="/blog/assets/js/30.1158f56f.js"><link rel="prefetch" href="/blog/assets/js/4.c0f4c928.js"><link rel="prefetch" href="/blog/assets/js/5.a69dfd84.js"><link rel="prefetch" href="/blog/assets/js/6.2d4b5bad.js"><link rel="prefetch" href="/blog/assets/js/7.728ad095.js"><link rel="prefetch" href="/blog/assets/js/8.17b33111.js"><link rel="prefetch" href="/blog/assets/js/9.c1e3802f.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.a6f4041f.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-999d3bb4><div data-v-999d3bb4><div id="loader-wrapper" class="loading-wrapper" data-v-2c578df8 data-v-999d3bb4 data-v-999d3bb4><div class="loader-main" data-v-2c578df8><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-067bd032 data-v-999d3bb4 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>不眠</h3> <p class="description" data-v-067bd032 data-v-067bd032>生活不仅需要氧气，更需要勇气</p> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-999d3bb4><header class="navbar" data-v-999d3bb4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/1.png" alt="不眠" class="logo"> <span class="site-name">不眠</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-999d3bb4></div> <aside class="sidebar" data-v-999d3bb4><div class="personal-info-wrapper" data-v-e2878dae data-v-999d3bb4><img src="/blog/1.png" alt="author-avatar" class="personal-img" data-v-e2878dae> <h3 class="name" data-v-e2878dae>
    william
  </h3> <div class="num" data-v-e2878dae><div data-v-e2878dae><h3 data-v-e2878dae>19</h3> <h6 data-v-e2878dae>Articles</h6></div> <div data-v-e2878dae><h3 data-v-e2878dae>0</h3> <h6 data-v-e2878dae>Tags</h6></div></div> <ul class="social-links" data-v-e2878dae></ul> <hr data-v-e2878dae></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-067bd032 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>重识音频</h3> <!----> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-999d3bb4><main class="page"><section><div class="page-title"><h1 class="title">重识音频</h1> <div data-v-10e19382><i class="iconfont reco-account" data-v-10e19382><span data-v-10e19382>william</span></i> <i class="iconfont reco-date" data-v-10e19382><span data-v-10e19382>1/1/2021</span></i> <!----> <!----></div></div> <div class="theme-reco-content content__default"><blockquote><p><code>我们平时在互联网上听到的声音，都是先经过录制后，再传输到互联网上的。比如歌曲、电影、主播等的声音。</code></p></blockquote> <h2 id="_1-pcm"><a href="#_1-pcm" class="header-anchor">#</a> 1 PCM</h2> <p>录音的原理可以简单理解为：<code>把声源的振动记录下来，需要时再让某个物体按照记录下来的振动规律去振动，就会产生与原来一样的声音。</code></p> <p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c5dd7e0db72f4ea698b5f786f8403f5d~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310121149953-189520171.png"></p> <p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2315612f94a74a298df6cbbcf6f38dd7~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310121152546-1765363508.png"></p> <p>如何把声音（声源的振动）记录下来呢？声音属于模拟信号，但更便于计算机处理和存储的是数字信号（二进制编码），所以需要将<strong>模拟信号</strong>（Analog Signal）转成<strong>数字信号</strong>（Digital Signal）后进行存储。这一过程，我们可以称之为：音频数字化
。</p> <p><code>模拟信号与数字信号的比喻</code></p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/053d03562f814347b7eb6a3d11a8ae7b~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310124628437-1142357612.png"></p> <p><code>模拟信号与数字信号的转换</code></p> <p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/37f856fa3cea4d7282c50b942c355966~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310124630934-1929901915.jpg"></p> <blockquote><p>将音频数字化的常见技术方案是脉冲编码调制（<strong>PCM</strong>，Pulse Code Modulation），主要过程是：<strong>采样 → 量化 → 编码</strong></p></blockquote> <p>模拟信号转数字信号</p> <p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7de51d8698754d698e3d136d1a361b82~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310153043339-940528055.webp"></p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8f73e5541fb3474b9febc3913b091dbc~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310153515352-366749255.png"></p> <h3 id="采样"><a href="#采样" class="header-anchor">#</a> 采样</h3> <p>模拟信号的波形是无限光滑的，可以看成由无数个点组成，由于存储空间是相对有限的，数字编码过程中，必须要对波形的点进行采样。<strong>采样</strong>（Sampling）：每隔一段时间采集一次模拟信号的样本，是一个在时间上将模拟信号离散化（把连续信号转换成离散信号）的过程。</p> <h3 id="采样率"><a href="#采样率" class="header-anchor">#</a> 采样率</h3> <p>每秒采集的样本数量，称为<strong>采样率</strong>（采样频率，采样速率，Sampling Rate）。比如，采样率44.1kHz表示1秒钟采集44100个样本。</p> <h3 id="采样定理"><a href="#采样定理" class="header-anchor">#</a> 采样定理</h3> <p>根据[<a href="https://zh.wikipedia.org/wiki/%E9%87%87%E6%A0%B7%E5%AE%9A%E7%90%86" target="_blank" rel="noopener noreferrer">采样定理<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>]（奈奎斯特–香农采样定理，Nyquist-Shannon sampling theorem）得知：只有当采样率高于声音信号最高频率的<strong>2</strong>倍时，才能把采集的声音信号唯一地还原成原来的声音。人耳能够感觉到的最高声音频率为20000Hz，因此为了满足人耳的听觉要求，需要至少每秒进行40000次采样（40kHz采样率）。这就是为什么常见的CD的采样率为44.1kHz。电话、无线对讲机、无线麦克风等的采样率是8kHZ。</p> <h3 id="量化"><a href="#量化" class="header-anchor">#</a> 量化</h3> <p><strong>量化</strong>（Quantization）：将每一个采样点的样本值数字化。</p> <h3 id="位深度"><a href="#位深度" class="header-anchor">#</a> 位深度</h3> <p><strong>位深度</strong>
（采样精度，采样大小，Bit Depth）：使用多少个二进制位来存储一个采样点的样本值。位深度越高，表示的振幅越精确。常见的CD采用16bit的位深度，能表示65536（216）个不同的值。DVD使用24bit的位深度，大多数电话设备使用8bit的位深度。</p> <p><code>不同采样率、位深度对比</code> <img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c4e3bf48f82a4ca192c52abb6e77a37f~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210310162126093-1629151210.png"></p> <h3 id="编码"><a href="#编码" class="header-anchor">#</a> 编码</h3> <p><strong>编码</strong>：将采样和量化后的数字数据转成二进制码流。</p> <h3 id="其他概念"><a href="#其他概念" class="header-anchor">#</a> 其他概念</h3> <h4 id="声道-channel"><a href="#声道-channel" class="header-anchor">#</a> 声道（Channel）</h4> <p>单声道产生一组声波数据，双声道（立体声）产生两组声波数据。
采样率44.1kHZ、位深度16bit的1分钟立体声PCM数据有多大？</p> <ul><li>采样率 * 位深度 * 声道数 * 时间</li> <li><em>44100 * 16 * 2 * 60 / 8 ≈ 10.34MB</em></li></ul> <p>1分钟10.34MB，这对于大部分用户来说是不能接受的。要想在不改变音频时长的前提下，降低音频数据的大小，只有2种方法：降低采样指标、压缩。降低采样指标是不可取的，会导致音频质量下降，用户体验变差，因此专家们研发了各种压缩方案。</p> <h3 id="比特率"><a href="#比特率" class="header-anchor">#</a> 比特率</h3> <p><strong>比特率</strong>（Bit Rate），指单位时间内传输或处理的比特数量，单位是：比特每秒（bit/s或bps），还有：千比特每秒（Kbit/s或Kbps）、兆比特每秒（Mbit/s或Mbps）、吉比特每秒（Gbit/s或Gbps）、太比特每秒（Tbit/s或Tbps）。</p> <p>采样率44.1kHZ、位深度16bit的立体声PCM数据的比特率是多少？</p> <ul><li>采样率 * 位深度 * 声道数</li> <li><em>44100 * 16 * 2 = 1411.2Kbps</em></li></ul> <p>通常，采样率、位深度越高，数字化音频的质量就越好。从比特率的计算公式可以看得出来：比特率越高，数字化音频的质量就越好。</p> <h3 id="信噪比"><a href="#信噪比" class="header-anchor">#</a> 信噪比</h3> <p><strong>信噪比</strong>（Signal-to-noise ratio，SNR，S/N，讯噪比），指信号与噪声的比例，用于比较所需信号的强度与背景噪声的强度，以分贝（dB）为单位。</p> <p>位深度限制了信噪比的最大值，它们的关系如下表所示。</p> <table><thead><tr><th>位深度</th> <th>信噪比</th></tr></thead> <tbody><tr><td>4</td> <td>24.08</td></tr> <tr><td>8</td> <td>48.16</td></tr> <tr><td>11</td> <td>66.22</td></tr> <tr><td>12</td> <td>72.24</td></tr> <tr><td>16</td> <td>96.33</td></tr> <tr><td>18</td> <td>108.37</td></tr> <tr><td>20</td> <td>120.41</td></tr> <tr><td>24</td> <td>144.49</td></tr> <tr><td>32</td> <td>192.66</td></tr> <tr><td>48</td> <td>288.99</td></tr> <tr><td>64</td> <td>385.32</td></tr></tbody></table> <h2 id="_2-音频的编码与解码"><a href="#_2-音频的编码与解码" class="header-anchor">#</a> 2 音频的编码与解码</h2> <h3 id="编码-encode"><a href="#编码-encode" class="header-anchor">#</a> 编码（Encode）</h3> <p>PCM数据可以理解为是：<strong>未经压缩的原始音频数据</strong>，体积比较大，为了更便于存储和传输，一般都会使用某种<strong>音频编码</strong>对它进行编码压缩，然后再存成某种<strong>音频文件格式</strong>。</p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/cfe8c8df8e834d37abe145e9dccadbcf~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210315203502644-1869060401.png">
压缩分为<strong>无损</strong>压缩和<strong>有损</strong>压缩。</p> <ul><li><p><strong>无损</strong>压缩</p> <ul><li>解压后<strong>可以</strong>完全还原出原始数据</li> <li>压缩比<strong>小</strong>，体积<strong>大</strong></li></ul></li> <li><p><strong>有损</strong>压缩</p> <ul><li>解压后<strong>不能</strong>完全还原出原始数据，会丢失一部分信息</li> <li>压缩比<strong>大</strong>，体积<strong>小</strong></li> <li>压缩比越大，丢失的信息就越多，还原后的信号失真就会越大</li> <li>一般是通过<strong>舍弃原始数据中对人类听觉不重要的部分</strong>，达成压缩成较小文件的目的</li></ul></li> <li><p>压缩比 = 未压缩大小 / 压缩后大小</p></li></ul> <h3 id="解码-decode"><a href="#解码-decode" class="header-anchor">#</a> 解码（Decode）</h3> <p>当需要播放音频时，得先解码（解压缩）出PCM数据，然后再进行播放。</p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/53099f4ad0b245a7977b559b43649472~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210315203603424-398158962.png"></p> <h2 id="_3-常见的音频编码和文件格式"><a href="#_3-常见的音频编码和文件格式" class="header-anchor">#</a> 3 常见的音频编码和文件格式</h2> <p>需要注意的是：<strong>音频文件格式并不等于音频编码</strong>。比如：</p> <ul><li><strong>WAV</strong>只是一种文件格式，并不是一种编码</li> <li><strong>FLAC</strong>既是一种文件格式，又是一种编码</li></ul> <p>下面对常见的音频编码和文件格式做一个简介，以后有需要时再进行详细介绍。</p> <table><thead><tr><th>名称</th> <th>无损压缩</th> <th>文件扩展名</th></tr></thead> <tbody><tr><td>Monkey's Audio</td> <td>✔️</td> <td>.ape</td></tr> <tr><td>FLAC（Free Lossless Audio Codec）</td> <td>✔️</td> <td>.flac</td></tr> <tr><td>ALAC（Apple Lossless Audio Codec）</td> <td>✔️</td> <td>.m4a/.caf</td></tr> <tr><td>MP3（MPEG Audio Layer III）</td> <td>❌</td> <td>.mp3</td></tr> <tr><td>WMA（Windows Media Audio）</td> <td>❌</td> <td>.wma</td></tr> <tr><td>AAC（Advanced Audio Coding）</td> <td>❌</td> <td>.acc/.mp4/.m4a</td></tr> <tr><td>Vorbis</td> <td>❌</td> <td>.ogg</td></tr> <tr><td>Speex</td> <td>❌</td> <td>.spx</td></tr> <tr><td>Opus</td> <td>❌</td> <td>.opus</td></tr> <tr><td>Ogg</td> <td></td> <td>.ogg</td></tr> <tr><td>WAV（Waveform Audio File Format）</td> <td></td> <td>.wav</td></tr> <tr><td>AIFF（Audio Interchange File Format）</td> <td></td> <td>.aiff、.aif</td></tr></tbody></table> <h3 id="_3-1-无损"><a href="#_3-1-无损" class="header-anchor">#</a> 3-1 无损</h3> <h4 id="_3-1-1-monkey-s-audio"><a href="#_3-1-1-monkey-s-audio" class="header-anchor">#</a> 3-1-1 Monkey's Audio</h4> <p>Monkey's Audio，是一种<strong>无损</strong>的音频编码和文件格式，文件扩展名为 <strong>.ape</strong>，压缩率一般在55%左右。</p> <h4 id="_3-1-2-flac"><a href="#_3-1-2-flac" class="header-anchor">#</a> 3-1-2 FLAC</h4> <p>FLAC（Free Lossless Audio Codec），是一种<strong>无损</strong>的音频编码和文件格式，文件扩展名为 <strong>.flac</strong>。虽然压缩率稍有不及Monkey's Audio，但FLAC技术更先进，占用资源更低，有更多的平台及硬件产品支持FLAC。</p> <h4 id="_3-1-3-alac"><a href="#_3-1-3-alac" class="header-anchor">#</a> 3-1-3 ALAC</h4> <p>ALAC（Apple Lossless Audio Codec），是由Apple开发的一种<strong>无损</strong>的音频编码，文件扩展名为 <strong>.m4a</strong>、 <strong>.caf</strong>。</p> <h3 id="_3-2-有损"><a href="#_3-2-有损" class="header-anchor">#</a> 3-2 有损</h3> <h4 id="_3-2-1-mp3"><a href="#_3-2-1-mp3" class="header-anchor">#</a> 3-2-1 MP3</h4> <p>MP3（MPEG Audio Layer III），是非常流行的一种<strong>有损</strong>音频编码和文件格式，文件扩展名为 <strong>.mp3</strong>。</p> <ul><li>第1版是：MPEG-1 Audio Layer III，属于国际标准<a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=22412" target="_blank" rel="noopener noreferrer">ISO/IEC 11172-3<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>第2版是：MPEG-2 Audio Layer III，属于国际标准<a href="http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?csnumber=26797" target="_blank" rel="noopener noreferrer">ISO/IEC 13818-3<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>第3版是：MPEG-2.5 Audio Layer III，并不是由MPEG官方开发的，不是公认的标准</li></ul> <h4 id="_3-2-2-wma"><a href="#_3-2-2-wma" class="header-anchor">#</a> 3-2-2 WMA</h4> <p>WMA（Windows Media Audio），是由Microsoft开发的音频编码和文件格式，文件扩展名为 <strong>.wma</strong>。包括4种类型：</p> <ul><li>WMA：原始的WMA编解码器，作为MP3的竞争者，属于<strong>有损</strong>音频编码</li> <li>WMA Pro：支持更多声道和更高质量的音频，属于<strong>有损</strong>音频编码</li> <li>WMA Lossless：属于<strong>无损</strong>音频编码</li> <li>WMA Voice：属于<strong>有损</strong>音频编码</li></ul> <h4 id="_3-2-3-aac"><a href="#_3-2-3-aac" class="header-anchor">#</a> 3-2-3 AAC</h4> <p>AAC（Advanced Audio Coding），是由Fraunhofer IIS、杜比实验室、AT&amp;T、Sony、Nokia等公司共同开发的<strong>有损</strong>音频编码和文件格式，压缩比通常为18:1。</p> <p>AAC被设计为MP3格式的后继产品，通常在相同的比特率下可以获得比MP3更高的声音质量，是iPhone、iPod、iPad、iTunes的标准音频格式。</p> <p>AAC编码的文件扩展名主要有3种：</p> <ul><li><p><strong>.acc</strong>：传统的AAC编码，使用MPEG-2 Audio Transport Stream（ADTS）容器</p></li> <li><p><strong>.mp4</strong>：使用了MPEG-4 Part 14的简化版即3GPP Media Release 6 Basic（3gp6）进行封装的AAC编码</p></li> <li><p><strong>.m4a</strong>：为了区别纯音频MP4文件和包含视频的MP4文件而由Apple公司使用的扩展名</p> <ul><li>Apple iTunes对纯音频MP4文件采用了 <strong>.m4a</strong>文件扩展名</li> <li>M4A的本质和音频MP4相同，故音频MP4文件可以直接更改文件扩展名为 <strong>.m4a</strong></li></ul></li></ul> <h4 id="_3-2-4-vorbis"><a href="#_3-2-4-vorbis" class="header-anchor">#</a> 3-2-4 Vorbis</h4> <p>Vorbis，是由Xiph.Org基金会开发的一种<strong>有损</strong>音频编码。通常以Ogg作为容器格式，所以常合称为Ogg Vorbis，文件扩展名为 <strong>.ogg</strong>。</p> <h4 id="_3-2-5-speex"><a href="#_3-2-5-speex" class="header-anchor">#</a> 3-2-5 Speex</h4> <p>Speex，是由Xiph.Org基金会开发的一种<strong>有损</strong>音频编码和文件格式，文件扩展名为 <strong>.spx</strong>。</p> <h4 id="_3-2-6-opus"><a href="#_3-2-6-opus" class="header-anchor">#</a> 3-2-6 Opus</h4> <p>Opus，是由Xiph.Org基金会开发的一种<strong>有损</strong>音频编码和文件格式，文件扩展名为 <strong>.opus</strong>。用以取代Vorbis和Speedx。经过多次盲听测试，在任何给定的比特率下都比其他标准音频格式具有更高的质量，包括MP3、AAC。</p> <h3 id="_3-3-文件格式"><a href="#_3-3-文件格式" class="header-anchor">#</a> 3-3 文件格式</h3> <h4 id="_3-3-1-ogg"><a href="#_3-3-1-ogg" class="header-anchor">#</a> 3-3-1 Ogg</h4> <p>Ogg是一种多媒体文件格式，由Xiph.Org基金会所维护，可以纳入各式各样的音视频编码（音频、视频都可以），文件扩展名常为 <strong>.ogg</strong>。</p> <p>Ogg常用的音频编码有：</p> <ul><li>有损压缩：Speex、Vorbis、Opus</li> <li>无损压缩：FLAC</li> <li>未压缩：PCM</li></ul> <h4 id="_3-3-2-wav"><a href="#_3-3-2-wav" class="header-anchor">#</a> 3-3-2 WAV</h4> <p>WAV（Waveform Audio File Format），是由IBM和Microsoft开发的音频文件格式，扩展名是 <strong>.wav</strong>，通常采用PCM编码，常用于Windows系统中。
<a href="http://soundfile.sapp.org/doc/WaveFormat/" target="_blank" rel="noopener noreferrer">WAV的文件格式<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>如下图所示，前面有44个字节的文件头，紧跟在后面的就是音频数据（比如PCM数据）。</p> <p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6cdaa41d2bd04f56a449bf4d8eee9d75~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210311190649736-42996929.gif"></p> <p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c9456f1c35ab4f9c9548ab4e4ea4851e~tplv-k3u1fbpfcp-watermark.image?" alt="497279-20210311190654247-121239230.gif"></p> <ul><li>NumChannels：声道数</li> <li>SampleRate：采样率（Hz）</li> <li>ByteRate：每秒多少个字节（Byte/s）</li> <li>BitsPerSample：位深度</li></ul> <h4 id="_3-3-3-aiff"><a href="#_3-3-3-aiff" class="header-anchor">#</a> 3-3-3 AIFF</h4> <p>AIFF（Audio Interchange File Format），由Apple开发的音频文件格式，扩展名是 <strong>.aiff</strong>、 <strong>.aif</strong>。跟WAV一样，通常采用PCM编码，常用于Mac系统中。</p> <h3 id="有损和无损"><a href="#有损和无损" class="header-anchor">#</a> 有损和无损</h3> <p>根据采样率和位深度可以得知：相对于自然界的信号，音频编码最多只能做到无限接近，任何数字音频编码方案都是有损的，因为无法完全还原。目前能够达到最高保真水平的就是PCM编码，因此，PCM约定俗成叫做<strong>无损</strong>音频编码，被广泛用于素材保存及音乐欣赏，CD、DVD以及常见的<strong>WAV</strong>文件中均有应用。</p> <p>但并不意味着PCM就能够确保信号绝对保真，PCM也只能做到最大程度的无限接近。我们习惯性的把MP3列入<strong>有损</strong>音频编码范畴，是相对于PCM编码的。要做到真正的无损是困难的，就像用数字去表达圆周率，不管精度多高，也只是无限接近，而不是真正等于圆周率的值。</p></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/8/2022, 11:40:30 AM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-92abcef6><li class="level-2" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_1-pcm" class="sidebar-link reco-side-_1-pcm" data-v-92abcef6>1 PCM</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#采样" class="sidebar-link reco-side-采样" data-v-92abcef6>采样</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#采样率" class="sidebar-link reco-side-采样率" data-v-92abcef6>采样率</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#采样定理" class="sidebar-link reco-side-采样定理" data-v-92abcef6>采样定理</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#量化" class="sidebar-link reco-side-量化" data-v-92abcef6>量化</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#位深度" class="sidebar-link reco-side-位深度" data-v-92abcef6>位深度</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#编码" class="sidebar-link reco-side-编码" data-v-92abcef6>编码</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#其他概念" class="sidebar-link reco-side-其他概念" data-v-92abcef6>其他概念</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#比特率" class="sidebar-link reco-side-比特率" data-v-92abcef6>比特率</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#信噪比" class="sidebar-link reco-side-信噪比" data-v-92abcef6>信噪比</a></li><li class="level-2" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_2-音频的编码与解码" class="sidebar-link reco-side-_2-音频的编码与解码" data-v-92abcef6>2 音频的编码与解码</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#编码-encode" class="sidebar-link reco-side-编码-encode" data-v-92abcef6>编码（Encode）</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#解码-decode" class="sidebar-link reco-side-解码-decode" data-v-92abcef6>解码（Decode）</a></li><li class="level-2" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_3-常见的音频编码和文件格式" class="sidebar-link reco-side-_3-常见的音频编码和文件格式" data-v-92abcef6>3 常见的音频编码和文件格式</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_3-1-无损" class="sidebar-link reco-side-_3-1-无损" data-v-92abcef6>3-1 无损</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_3-2-有损" class="sidebar-link reco-side-_3-2-有损" data-v-92abcef6>3-2 有损</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#_3-3-文件格式" class="sidebar-link reco-side-_3-3-文件格式" data-v-92abcef6>3-3 文件格式</a></li><li class="level-3" data-v-92abcef6><a href="/blog/blogs/AudioAndVideo/0712.html#有损和无损" class="sidebar-link reco-side-有损和无损" data-v-92abcef6>有损和无损</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-a008c6ba data-v-a008c6ba><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-a008c6ba><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-a008c6ba></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-a008c6ba></path></svg></div></div></div>
    <script src="/blog/assets/js/app.bd1ef45e.js" defer></script><script src="/blog/assets/js/3.ba154db2.js" defer></script><script src="/blog/assets/js/1.1f0d1f23.js" defer></script><script src="/blog/assets/js/12.2f9bf96e.js" defer></script>
  </body>
</html>
